IRCBot::Plugin.define "die" do
	help_string				"Asks for me to leave the channel. Three votes and I'm out. Use \"die\" again to unvote."
	@leavearray	=			{}
	@usersarray	=			{}
	
	def command(user,target,message,usermask)
		if get_plugin('auth').is_auth_user?(usermask) then
			send("QUIT #{message}")
		else # Borrowed code from OldMarco.
			target = target.downcase
			user = usermask.split('!')[1]
			if target.start_with?('#') then
				@leavearray[target] =	0	if @leavearray[target] == nil
				@usersarray[target] =	[]	if @usersarray[target] == nil
				if @usersarray[target].include?(user) then
					@leavearray[target] -=		1
					@usersarray[target].delete	user
					privmsg(target,"Vote removed. #{@leavearray[target]} votes remaining.")
				else
					@leavearray[target]	+=		1
					@usersarray[target].push	user
					privmsg(target,"Vote added. There are now #{@leavearray[target]} people asking me to leave.")
					if @leavearray[target] >= 3 then
						privmsg(target,'Three votes, I\'m out!')
						$ircbot.send("PART #{target}")
						@leavearray[target] = 0
						@usersarray[target] = []
					end
				end
			else
				privmsg(target,"What the cruds are you trying to do?")
			end
		end
	end
end
